import global from "../../global";
import Player from "./player";
import Point_ts, { Mark } from "./point";

const {ccclass, property} = cc._decorator;

@ccclass
export default class Effect extends cc.Component {

    //特效层  
    @property(cc.Node)
    Layer_effect:cc.Node = null;

    //各种提示点击的图片
    @property(cc.SpriteFrame)
    Arr_sf_tip:Array<cc.SpriteFrame> = [];        //0：可以行动，1：可出出大，2：可以移动，3：可以攻击，4：可以施法
    
    //大子死亡特效
    @property(cc.Prefab)
    Prefab_die:cc.Prefab = null;
    //小子喝药特效
    @property(cc.Prefab)
    Prefab_smalldrink:cc.Prefab = null;
    //大子符咒特效
    @property(cc.Prefab)
    Prefab_bigSpell:cc.Prefab = null;
    //炮弹攻击特效
    @property(cc.Prefab)
    Prefab_shell:cc.Prefab = null;  
    //顽石自爆特效
    @property(cc.Prefab)
    Prefab_boneBoom:cc.Prefab = null;  
    //狙炮瞄准特效
    @property(cc.Prefab)
    Prefab_batteryAim:cc.Prefab = null;   
    //冰冻手雷
    @property(cc.Prefab)
    Prefab_bdsl1:cc.Prefab = null; 
    //冰冻手雷爆炸
    @property(cc.Prefab)
    Prefab_bdsl2:cc.Prefab = null; 
    //瘟疫传播
    @property(cc.Prefab)
    Prefab_wycb:cc.Prefab = null; 
    //步步生莲
    @property(cc.Prefab)
    Prefab_bbsl:cc.Prefab = null; 

    //地狱杀伐阵
    @property(cc.Prefab)
    Prefab_bloody:cc.Prefab = null; 
    //诡变无常阵
    @property(cc.Prefab)
    Prefab_variable:cc.Prefab = null; 
    //九曲黄河阵
    @property(cc.Prefab)
    Prefab_maze:cc.Prefab = null; 
    //迷雾森林阵
    @property(cc.Prefab)
    Prefab_fog:cc.Prefab = null; 
    //佛法慈悲阵
    @property(cc.Prefab)
    Prefab_mercy:cc.Prefab = null; 
    //风雪冰霜阵
    @property(cc.Prefab)
    Prefab_snow:cc.Prefab = null; 

    onLoad(){
        global.effect = this;
    }

    /**
     * 播放顽石爆炸特效
     */
    playBoneBoom(v3:cc.Vec3){
        global.music_ts.playEffect("Audio_boneBoom");
        let node = cc.instantiate(this.Prefab_boneBoom);
        node.setPosition(v3);
        this.Layer_effect.addChild(node);
        cc.tween(node).to(1,{scale:5,opacity:100},{easing:'sineOut'}).call(()=>{node.destroy();}).start();
    }

    /**
     * 播放炮弹飞过去
     */
    playShell(start:cc.Vec3,end:cc.Vec3){
        global.music_ts.playEffect("Audio_battery");
        let node = cc.instantiate(this.Prefab_shell);
        node.setPosition(start);
        this.Layer_effect.addChild(node);
        let action1 = cc.tween().to(.4,{scale:3},{easing:'sineOut'}).to(.4,{scale:1},{easing:'sineIn'}).call(()=>{node.destroy();});
        let action2 = cc.tween().to(.8,{position:end});
        cc.tween(node).parallel(action1,action2).start();
    }

    /**
     * 播放大子死亡特效
     */
    playBigDie(v3:cc.Vec3,color:cc.Color){
        global.music_ts.playEffect("Audio_die");
        let node = cc.instantiate(this.Prefab_die);
        node.setPosition(v3);
        node.color = color;
        this.Layer_effect.addChild(node);
        cc.tween(node).to(1,{scale:5,opacity:0}).call(()=>{node.destroy();}).start();
    }

    /**
     * 播放小子喝药剂特效
     */
    playSmalldrink(){
        let node = cc.instantiate(this.Prefab_smalldrink);
        global.UI.node.addChild(node);
        cc.tween(node).to(1,{scale:5,opacity:100}).call(()=>{node.destroy();}).start();
    }

    /**
     * 播放大子获得符咒
     */
    playBigSpell(v3:cc.Vec3){
        let node = cc.instantiate(this.Prefab_bigSpell);
        node.setPosition(v3);
        this.Layer_effect.addChild(node);
        cc.tween(node).to(1,{scale:5,opacity:100}).call(()=>{node.destroy();}).start();
    }

    /**
     * 播放狙炮瞄准特效
     */
    playJPAim(start:cc.Vec3,end:cc.Vec3,mark:Mark,color:cc.Color,flag:boolean){
        //炮飞到天上消失 true表示有视野
        if(flag){
            global.music_ts.playEffect("Audio_battery");
            let shell = cc.instantiate(this.Prefab_shell);
            shell.setPosition(start);
            this.Layer_effect.addChild(shell);
            cc.tween(shell).to(.4,{scale:3},{easing:'sineOut'}).call(()=>{shell.destroy();}).start();
        }
        //瞄准印记
        let aim = cc.instantiate(this.Prefab_batteryAim);
        aim.setPosition(end);
        this.Layer_effect.addChild(aim);
        aim.color = color;
        mark.node = aim;
        let action= cc.tween().to(.8,{scale:3,opacity:100}).delay(.2).to(.8,{scale:1,opacity:255}).delay(.2);
        cc.tween(aim).repeatForever(action).start();
    }

    /**
     * 播放狙炮打击特效
     */
    playJPHit(v3:cc.Vec3,node:cc.Node){
        node.destroy();
        let shell = cc.instantiate(this.Prefab_shell);
        shell.setPosition(v3);
        this.Layer_effect.addChild(shell);
        shell.scale = 3;
        cc.tween(shell).to(.4,{scale:1},{easing:'sineIn'}).call(()=>{
            shell.destroy();
            this.playBoneBoom(v3);
        }).start();
    }

    /**
     * 播放地狱杀伐阵
     */
    playDYSF(point_ts:Point_ts,player:Player){
        let v3 = point_ts.node.position;
        let node = cc.instantiate(this.Prefab_bloody);
        node.scale = 5;
        node.color = player.color;
        node.setPosition(v3);
        this.Layer_effect.addChild(node);
        //旋转动画
        let action1 = cc.tween().to(.5, {opacity: 150}).to(2, {opacity: 0}).delay(.5);
        cc.tween(node).repeatForever(action1).start();
        cc.tween(node).by(3, {angle: 90}).repeatForever().start();
        return node;
    }

    /**
     * 播放冰冻手雷
     */
    playBDSL(v3:cc.Vec3){
        //手雷从天而降
        let sl = cc.instantiate(this.Prefab_bdsl1);
        sl.setPosition(v3);
        this.Layer_effect.addChild(sl);
        sl.scale = 5;
        cc.tween(sl).to(.5,{scale:1},{easing:"sineIn"}).call(()=>{
            sl.destroy();
            //手雷消失，爆炸特效放大
            let boom = cc.instantiate(this.Prefab_bdsl2);
            boom.setPosition(v3);
            this.Layer_effect.addChild(boom);
            cc.tween(boom).to(.3,{scale:5,opacity:150},{easing:"sineOut"}).call(()=>{
                boom.destroy();
            }).start();
        }).start();
    }

    /**
     * 播放诡变无常阵法
     */
    playGBWC(point_ts:Point_ts,player:Player){
        let v3 = point_ts.node.position;
        let node = cc.instantiate(this.Prefab_variable);
        node.scale = 5;
        node.color = player.color;
        node.setPosition(v3);
        this.Layer_effect.addChild(node);
        //旋转动画
        let action1 = cc.tween().to(.5, {opacity: 150}).to(2, {opacity: 0}).delay(.5);
        cc.tween(node).repeatForever(action1).start();
        cc.tween(node).by(3, {angle: 90}).repeatForever().start();
        return node;
    }

    /**
     * 播放九曲黄河阵法
     */
    playJQHH(point_ts:Point_ts,player:Player){
        let v3 = point_ts.node.position;
        let node = cc.instantiate(this.Prefab_maze);
        node.scale = 5;
        node.color = player.color;
        node.setPosition(v3);
        this.Layer_effect.addChild(node);
        //旋转动画
        let action1 = cc.tween().to(.5, {opacity: 150}).to(2, {opacity: 0}).delay(.5);
        cc.tween(node).repeatForever(action1).start();
        cc.tween(node).by(3, {angle: 90}).repeatForever().start();
        return node;
    }

    /**
     * 播放迷雾森林阵法
     */
    playMWSL(point_ts:Point_ts,player:Player){
        let v3 = point_ts.node.position;
        let node = cc.instantiate(this.Prefab_fog);
        node.scale = 5;
        node.color = player.color;
        node.setPosition(v3);
        this.Layer_effect.addChild(node);
        //旋转动画
        let action1 = cc.tween().to(.5, {opacity: 150}).to(2, {opacity: 0}).delay(.5);
        cc.tween(node).repeatForever(action1).start();
        cc.tween(node).by(3, {angle: 90}).repeatForever().start();
        return node;
    }

    /**
     * 播放佛法慈悲阵法
     */
    playFFCB(point_ts:Point_ts,player:Player){
        let v3 = point_ts.node.position;
        let node = cc.instantiate(this.Prefab_mercy);
        node.scale = 5;
        node.color = player.color;
        node.setPosition(v3);
        this.Layer_effect.addChild(node);
        //旋转动画
        let action1 = cc.tween().to(.5, {opacity: 150}).to(2, {opacity: 0}).delay(.5);
        cc.tween(node).repeatForever(action1).start();
        cc.tween(node).by(3, {angle: 90}).repeatForever().start();
        return node;
    }

    /**
     * 播放风雪冰霜阵法
     */
    playFXBS(point_ts:Point_ts,player:Player){
        let v3 = point_ts.node.position;
        let node = cc.instantiate(this.Prefab_snow);
        node.scale = 5;
        node.color = player.color;
        node.setPosition(v3);
        this.Layer_effect.addChild(node);
        //旋转动画
        let action1 = cc.tween().to(.5, {opacity: 150}).to(2, {opacity: 0}).delay(.5);
        cc.tween(node).repeatForever(action1).start();
        cc.tween(node).by(3, {angle: 90}).repeatForever().start();
        return node;
    }

    /**
     * 播放瘟疫传播
     */
    playWYCB(v3:cc.Vec3){
        let node = cc.instantiate(this.Prefab_wycb);
        node.setPosition(v3);
        this.Layer_effect.addChild(node);
        node.scale = 1;
        cc.tween(node).to(1,{scale:5,opacity:100}).call(()=>{node.destroy();}).start();
    }

    /**
     * 步步生莲  移动后生效时触发
     */
    playBBSL(v3:cc.Vec3){
        let node = cc.instantiate(this.Prefab_bbsl);
        node.setPosition(v3);
        this.Layer_effect.addChild(node);
        node.scale = 1;
        cc.tween(node).to(1,{scale:5,opacity:100}).call(()=>{node.destroy();}).start();
    }
    
}
